package com.hdu.dwh.service.flink_service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FlinkJarService {
    @Autowired
    private FlinkWebRestService flinkWebRestService;

    /**
     * 根据jar包名称获取jar包ID
     * @param jarName
     * @return
     * @throws Exception
     */
    public String getJarIdbyName(String jarName) throws Exception {
        Map<String, Object> jars = flinkWebRestService.fetchFlinkUploadJars();
        List<Map<String, Object>> jarsList = (List<Map<String, Object>>) jars.get("files");
        for (Map<String, Object> jar : jarsList) {
            if (jar.get("name").equals(jarName)) {
                return (String) jar.get("id");
            }
        }
        throw new Exception("未找到对应的jar包: " + jarName);
    }
}
